/*
 * @Author: your name
 * @Date: 2021-02-01 18:13:58
 * @LastEditTime: 2021-02-04 00:29:32
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \wwwd:\凯哥购物项目\request\index.js
 */
let ajaxTimes = 0;
export const request = (params) => {

    let header = {...params.header };
    if (params.url.includes("/my/")) {
        header["Authorization"] = wx.getStorageSync('token');
    }
    ajaxTimes++;
    //显示加载中
    wx.showLoading({
            title: "加载中",
            mask: true
        })
        //定义公共url
    const baseUrl = "http://192.168.206.77:8000"
    return new Promise((resolve, reject) => {
        wx.request({
            ...params,
            header: header,
            url: baseUrl + params.url,
            success: (result) => {
                resolve(result.data);
            },
            fail: (err) => {
                reject(err);
            },
            complete: () => {
                ajaxTimes--;
                if (ajaxTimes === 0) {
                    wx.hideLoading();
                }


            }
        });
    })
}